package com.qidian.k12.controller;

import com.qidian.k12.dto.PageInfo;
import com.qidian.k12.pojo.Student;
import com.qidian.k12.service.StudentService;
import com.qidian.k12.util.K12Result;
import com.qidian.k12.util.ObjectTools;
import com.qidian.k12.vo.StudentQueryVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Student)表控制层
 *
 * @author makejava
 * @since 2021-10-28 17:57:25
 */
@RestController
@RequestMapping("student")
public class StudentController {
    /**
     * 服务对象
     */
    @Resource
    private StudentService studentService;

    @RequestMapping("/queryByNameAndNo")
    public K12Result queryByNameAndNo(String no, String name) {
        return studentService.queryByNameAndNo(no, name);
    }

    @PostMapping("/save")
    public K12Result save(@RequestBody Student student) {
        System.out.println(student.toString());
        return studentService.insert(student);
    }

    @PostMapping("/update")
    public K12Result update(@RequestBody Student student) {
        return studentService.update(student);
    }

    @GetMapping("/get")
    public Student student(String studentNo) {
        return studentService.queryById(studentNo);
    }

    @RequestMapping("/query")
    public PageInfo<Student> query(StudentQueryVo vo) {
        return studentService.query(ObjectTools.object2map(vo));
    }


}

